package com.spa.domain.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.application.command.admin.TicketAddCommand;
import com.spa.application.command.admin.TicketEditCommand;
import com.spa.application.dto.admin.TicketExportDTO;
import com.spa.application.query.admin.TicketQuery;
import com.spa.domain.entity.Ticket;
import com.spa.infrastructure.mapper.TicketMapperStruct;
import com.spa.infrastructure.repository.condition.TicketCondition;
import com.spa.infrastructure.repository.po.TicketPO;
import com.spa.infrastructure.repository.service.TicketRepositoryService;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class TicketService {

    @Resource
    private TicketRepositoryService ticketRepositoryService;

    public Long addTicket(TicketAddCommand command) {
        return ticketRepositoryService.addTicket(TicketMapperStruct.INSTANCE.command2Po(command));
    }

    public void offline(TicketEditCommand command) {
        TicketPO po = TicketMapperStruct.INSTANCE.command2Po(command);
        po.setIsDel(1);
        ticketRepositoryService.updateTicketById(po);
    }

    public Page<Ticket> page(TicketQuery query) {
        TicketCondition condition = new TicketCondition();
        condition.setName(query.getName());
        condition.setType(query.getType());
        return TicketMapperStruct.INSTANCE.po2Entity4Page(ticketRepositoryService.page(condition));
    }

    public Ticket infoById(Long id) {
        return TicketMapperStruct.INSTANCE.po2Entity(ticketRepositoryService.getById(id));
    }
    public List<Ticket> list(TicketQuery query){
        TicketCondition condition = new TicketCondition();
        condition.setName(query.getName());
        condition.setType(query.getType());
        return TicketMapperStruct.INSTANCE.po2Entity4List(ticketRepositoryService.list(condition));
    }
}
